package com.ruoyi.project.system.record.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.baseinfo.domain.TNewbornBaseinfo;
import com.ruoyi.project.system.baseinfo.service.ITNewbornBaseinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新生儿复检管理
 *
 * @author
 * @date 2021-03-31
 */
@Controller
@RequestMapping("/system/secondInspect")
public class TSecondInspectController extends BaseController
{
    private String prefix = "system/secondInspect";

    @Autowired
    private ITNewbornBaseinfoService tNewbornBaseinfoService;

    @GetMapping()
    public String list()
    {
        return prefix + "/list";
    }

    /**
     * 查询新生儿复检基本信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TNewbornBaseinfo tNewbornBaseinfo)
    {
        startPage();
        List<TNewbornBaseinfo> list = tNewbornBaseinfoService.selectTNewbornSecondInsepctList(tNewbornBaseinfo);
        return getDataTable(list);
    }

    /**
     * 导出新生儿复检基本信息列表
     */
    @Log(title = "新生儿基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TNewbornBaseinfo tNewbornBaseinfo)
    {
        List<TNewbornBaseinfo> list = tNewbornBaseinfoService.selectTNewbornSecondInsepctList(tNewbornBaseinfo);
        ExcelUtil<TNewbornBaseinfo> util = new ExcelUtil<TNewbornBaseinfo>(TNewbornBaseinfo.class);
        return util.exportExcel(list, "secondInspect");
    }

    /**
     * 新生儿新生儿复检
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TNewbornBaseinfo tNewbornBaseinfo = tNewbornBaseinfoService.selectTNewbornBaseinfoById(id);
        mmap.put("tNewbornBaseinfo", tNewbornBaseinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存新生儿复检信息
     */
    @Log(title = "新生儿基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TNewbornBaseinfo tNewbornBaseinfo)
    {
        return toAjax(tNewbornBaseinfoService.updateTNewbornSecondInspect(tNewbornBaseinfo));
    }

}
